﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using DevExpress.XtraReports.UI;

namespace Baocao
{
    public partial class BaoCao_SoQuy : System.Web.UI.Page
    {
        private SqlConnection appConn;
        private System.Globalization.CultureInfo cultureinfo = new System.Globalization.CultureInfo("vi-VN");
        public static string TenCty = "CÔNG TY CỔ PHẦN HIVI", DcCty = "ĐC:38 - Trường Chinh - Hà Nội", DtCty = "ĐT:(04)32343242", Loaipm = "Phần mềm bán hàng", Tenpm = "HIVI 2S PRO Mobie", Webpm = "www.hivi.com.vn";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["appConn"] != null)
            {
                appConn = (SqlConnection)Session["appConn"];
                if (!IsPostBack)
                {
                    Baocao.reportpage yourMaster = (Baocao.reportpage)this.Master;
                    yourMaster.ChangeTitle("Báo cáo tổng hợp hàng bán");

                    dttuNgay.Text = DateTime.Now.ToString("dd/MM/yyyy");
                    dtdenNgay.Text = DateTime.Now.ToString("dd/MM/yyyy");

                    drtaikhoan.DataSource = gettaikhoan();
                    drtaikhoan.DataValueField = "TkID";
                    drtaikhoan.DataTextField = "TkName";
                    drtaikhoan.DataBind();
                }
            }
            else
            {
                Response.Redirect("~\\Login.aspx");
            }

        }


        protected void btIn_Click(object sender, EventArgs e)
        {
            string ngaybd_bc = "", ngaykt_bc = "", ngaybd = "", ngaykt = "", taikhoan = "";
            try
            {
                if (!dttuNgay.Text.ToString().Equals(""))
                {
                    ngaybd_bc = DateTime.Parse(dttuNgay.Text, cultureinfo).ToString("yyyyMMdd");
                    ngaybd = DateTime.Parse(dttuNgay.Text, cultureinfo).ToString("dd/MM/yyyy");
                }
                if (!dtdenNgay.Text.ToString().Equals(""))
                {
                    ngaykt_bc = DateTime.Parse(dtdenNgay.Text, cultureinfo).ToString("yyyyMMdd");
                    ngaykt = DateTime.Parse(dtdenNgay.Text, cultureinfo).ToString("dd/MM/yyyy");
                }
                taikhoan = drtaikhoan.SelectedValue;
                DataSet ds = new DataSet();

                string s = "EXEC [fs_HG_BCQUY11]  '" + ngaybd_bc + "', '" + ngaykt_bc + "','" + taikhoan + "' ";
                hg3.hg3.sql.SQLRetrieve(appConn, s, "bc", ref ds);
                DataTable dt = ds.Tables["bc"];
                rptSoQuy rpt = new rptSoQuy();
                rpt.DataSource = dt;

                rpt.Parameters["tungay"].Value = ngaybd;
                rpt.Parameters["denngay"].Value = ngaykt;
                rpt.Parameters["Kho"].Value = "TẤT CẢ CÁC KHO";

                rpt.Parameters["tenCty"].Value = TenCty;
                rpt.Parameters["dcCty"].Value = DcCty;
                rpt.Parameters["dtCty"].Value = DtCty;

                rpt.Parameters["Tenpm"].Value = Tenpm;
                rpt.Parameters["Loaipm"].Value = Loaipm;
                rpt.Parameters["Webpm"].Value = Webpm;
                Session["Report"] = rpt;

                Response.Redirect("~\\Print.aspx");
            }
            catch (Exception ex)
            {
                return;
            }
        }     

        private DataTable gettaikhoan()
        {
            DataSet ds = new DataSet();
            hg3.hg3.sql.SQLRetrieve(appConn, "SELECT TkID, TkName FROM dmtk WHERE TkID IN ('111','1111','112','1121')", "dmtk", ref ds);
            DataTable dt = ds.Tables["dmtk"];
            return dt;
        }

    }
}
